//
//  IMChatBusinessCardCell.m
//  SISSAPP
//
//  Created by 优房网 on 2017/6/26.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSChatBusinessCardCell.h"
#import "EaseBubbleView+ChatBusinessCard.h"

static const CGFloat kCellHeight = 110.0f;
@implementation SISSChatBusinessCardCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier model:(id<IMessageModel>)model{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier model:model];
    if (self) {
        self.avatarSize = 40.f;
        self.avatarCornerRadius = 20.f;
        self.hasRead.hidden = YES;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (BOOL)isCustomBubbleView:(id)model{
    return YES;
}

- (void)setCustomModel:(id<IMessageModel>)model{
    UIImage *image = model.image;
    if (!image) {
        [self.bubbleView.imageView sd_setImageWithURL:[NSURL URLWithString:model.fileURLPath] placeholderImage:[UIImage imageNamed:model.failImageName]];
    } else {
        _bubbleView.imageView.image = image;
    }
    
    if (model.avatarURLPath) {
        [self.avatarView sd_setImageWithURL:[NSURL URLWithString:model.avatarURLPath] placeholderImage:model.avatarImage];
    } else {
        self.avatarView.image = model.avatarImage;
    }
}

- (void)setCustomBubbleView:(id)model{
    [_bubbleView setupBusinessCardBubbleView];
    
    _bubbleView.imageView.image = [UIImage imageNamed:@"shouyeliaotiankuangbai"];
}

- (void)updateCustomBubbleViewMargin:(UIEdgeInsets)bubbleMargin model:(id<IMessageModel>)mode{
    [_bubbleView updateBusinessCardMargin:bubbleMargin];
    _bubbleView.translatesAutoresizingMaskIntoConstraints = YES;
    
    CGFloat bubbleViewHeight = 84;// 气泡背景图高度
    CGFloat nameLabelHeight = 15;// 昵称label的高度
    
    if (mode.isSender) {
        _bubbleView.frame = CGRectMake(SCREEN_WIDTH - 273.5, nameLabelHeight, 213, bubbleViewHeight);
    }else{
        _bubbleView.frame = CGRectMake(55, nameLabelHeight, 213, bubbleViewHeight);
        
    }
    // 这里强制调用内部私有方法
//    [_bubbleView _setupConstraintsXX];
    
}

+ (NSString *)cellIdentifierWithModel:(id<IMessageModel>)model {
    return NSStringFromClass([self class]);
}


+ (CGFloat)cellHeightWithModel:(id<IMessageModel>)model {
    return kCellHeight;
}

- (void)setModel:(id<IMessageModel>)model {
    [super setModel:model];
    NSDictionary *dict = model.message.ext;
    UIColor *textColor = self.model.isSender ? COLOR(0xFFFFFF) : COLOR(0x334A60);
    self.bubbleView.userNameLabel.textColor = textColor;
    self.bubbleView.userPhoneLabel.textColor = textColor;
    self.bubbleView.phoneTitleLabel.textColor = textColor;
    self.bubbleView.userNameLabel.text = dict[@"name"];
    self.bubbleView.userPhoneLabel.text = dict[@"mobile"];
    _hasRead.hidden = YES;//名片消息不显示已读
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
//    NSString *imageName = self.model.isSender ? @"" : @"";
//    UIImage *image = self.model.isSender ? [[UIImage imageNamed:imageName] stretchableImageWithLeftCapWidth:30 topCapHeight:35] :
//    [[UIImage imageNamed:imageName] stretchableImageWithLeftCapWidth:20 topCapHeight:35];
    // 等待接入名片的背景图片
//        self.bubbleView.backgroundImageView.image = image;
}


@end
